package com.biz.redis.util;

import org.springframework.beans.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.context.*;
import org.springframework.stereotype.*;

/**
 * @Description 上下文工具
 * @Author liuxi
 * @Date 2024/4/21
 **/
@Component
public class SpringContextUtil implements ApplicationContextAware {

    @Autowired
    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringContextUtil.applicationContext = applicationContext;
    }

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public static Object getBean(Class type) {
        return applicationContext.getBean(type);
    }
}
